package com.hmeter.mongodb;

import java.net.UnknownHostException;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.mongodb.WriteResult;

public class MongoDbDeleteSamplerUtility {

	private MongoDbUtility mongoDbUtility = null;
	
	public MongoDbDeleteSamplerUtility(String host, int port, String dbName, String collectionName) throws UnknownHostException
	{
		mongoDbUtility = new MongoDbUtility(host, port, dbName, collectionName);
	}
	
	public MongoDbUtility getMongoDbUtility()
	{
		return mongoDbUtility;
	}
	
	public String deleteAllDocumentsFromCollection()
	{
		WriteResult result = mongoDbUtility.getMongoDbCollection().remove(new BasicDBObject());
		return "Number of records deleted: " + result.getN();
	}
	
	public String deleteDocumentFromCollectionByClause(List<BasicDBObject> objects, String operator)
	{
		BasicDBObject query = new BasicDBObject();
		query.put(operator, objects);
		WriteResult result = mongoDbUtility.getMongoDbCollection().remove(query);
		return "Number of records deleted: " + result.getN();
	}
}
